package com.zhonggong.sixteen;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

//写程序将整数1到100写入到二进制文件，再读出这些整数并计算它们的和.
public class Three {
	
	public static int count(String fileName) throws IOException
	{
		int sum = 0;
		File file = new File(fileName);
		file.createNewFile();
		FileOutputStream fos = new FileOutputStream(file);
		for(int i=1;i<=100;i++)fos.write(i);
		fos.close();
		FileInputStream fis = new FileInputStream(file);
		for(int i = 0;i<file.length();i++)sum += fis.read();
		return sum;
		
	}
	
	public static void main(String[] args) throws IOException {
		System.out.println(Three.count("count.txt"));
	}
	
}
